package model;

import java.awt.Desktop;
import java.io.File;
import java.io.IOException;

/**
 * The abstract class to control the different types of papers.
 * @author Kevin Anderson
 */
public abstract class Paper {

	/**
	 * The file associated with the paper.  Available to children.
	 */
	protected File my_file;
	
	/**
	 * The ID of the Paper.  Available to children.
	 */
	protected int my_id;
	
	/**
	 * Used to assist with Platform independence.  Not currently utilized in implementation.
	 */
	public static String DS = System.getProperty("path.separator");
	
	
	/**
	 * No Param constructor to allow creation of a Paper for development purposes.
	 */
	public Paper()
	{
		my_file = null;
	}

	/**
	 * Uses the computer's default application to open <code>my_file</code>.
	 * @return Will return <code>true</code> if the file opens successfully, <code>false</code> otherwise.
	 */
	public boolean open()
	{
		try {
			Desktop.getDesktop().open(my_file);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			System.err.println("FileNotFound");
			e.printStackTrace();
			return false;
		}
		
		return true;
	}
	
	/**
	 * Uses the provided path to set the my_file field.
	 * @param path The path of the file to use.
	 * @return Will return <code>true</code> if the file is created successfully, <code>false</code> otherwise.
	 */
	private final boolean setFile(String path)
	{
		my_file = new File(path);
		
		if (my_file == null)
			return false;
		
		return true;
	}
	
	/**
	 * Exposes the Paper's File Object
	 * @return The Paper's file object.
	 */
	public File getFile()
	{
		return my_file;
	}
	
	
	/**
	 * Allows fileParser to set the my_file attribute.
	 * @param the_file The file to store.
	 */
	public void setFile(File the_file)
	{
		my_file = the_file;
	}
	
	/**
	 * Allows fileParser to set the my_ID attribte
	 * @param id The value to use when setting the ID.
	 */
	public void setID(int id)
	{
		my_id = id;
	}	
	
	
}